<template>
  <div class="menu-management">
    <div class="page-header">
      <h2>菜单管理</h2>
      <div class="header-actions">
        <el-button type="info" @click="showDocumentation" :icon="Document">使用说明</el-button>
        <el-button type="primary" @click="handleAdd" :icon="Plus">新增菜单</el-button>
        <el-button @click="refreshData" :icon="Refresh">刷新</el-button>
      </div>
    </div>

    <div class="table-container">
      <el-table
        :data="menuData"
        v-loading="loading"
        row-key="id"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        :expand-row-keys="expandedKeys"
        @expand-change="handleExpandChange"
        stripe
        border
        class="animated-table"
      >
        <el-table-column prop="menuName" label="菜单名称" min-width="200">
          <template #default="{ row }">
            <el-icon v-if="row.icon" style="margin-right: 5px;">
              <component :is="row.icon" />
            </el-icon>
            {{ row.menuName }}
          </template>
        </el-table-column>
        
        <el-table-column prop="menuCode" label="菜单编码" min-width="150" />
        
        <el-table-column prop="menuType" label="菜单类型" width="100">
          <template #default="{ row }">
            <el-tag 
              :type="getMenuTypeTagType(row.menuType)"
              size="small"
            >
              {{ getMenuTypeText(row.menuType) }}
            </el-tag>
          </template>
        </el-table-column>
        
        <el-table-column prop="path" label="路由路径" min-width="150" />
        
        <el-table-column prop="component" label="组件路径" min-width="150" />
        
        <el-table-column prop="sort" label="排序" width="80" />
        
        <el-table-column prop="status" label="状态" width="80">
          <template #default="{ row }">
            <el-tag 
              :type="row.status === 1 ? 'success' : 'danger'"
              size="small"
            >
              {{ row.status === 1 ? '启用' : '禁用' }}
            </el-tag>
          </template>
        </el-table-column>
        
        <el-table-column prop="createTime" label="创建时间" width="160">
          <template #default="{ row }">
            {{ formatDateTime(row.createTime) }}
          </template>
        </el-table-column>
        
        <el-table-column label="操作" width="200" fixed="right">
          <template #default="{ row }">
            <el-button 
              type="primary" 
              size="small" 
              @click="handleEdit(row)"
              :icon="Edit"
            >
              编辑
            </el-button>
            <el-button 
              type="danger" 
              size="small" 
              @click="handleDelete(row)"
              :icon="Delete"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 新增/编辑菜单对话框 -->
    <el-dialog
      :title="dialogTitle"
      v-model="dialogVisible"
      width="600px"
      :close-on-click-modal="false"
    >
      <el-form
        ref="menuFormRef"
        :model="menuForm"
        :rules="menuFormRules"
        label-width="100px"
      >
        <el-form-item label="菜单名称" prop="menuName">
          <el-input v-model="menuForm.menuName" placeholder="请输入菜单名称" />
        </el-form-item>
        
        <el-form-item label="菜单编码" prop="menuCode">
          <el-input v-model="menuForm.menuCode" placeholder="请输入菜单编码" />
        </el-form-item>
        
        <el-form-item label="菜单类型" prop="menuType">
          <el-select v-model="menuForm.menuType" placeholder="请选择菜单类型" style="width: 100%">
            <el-option label="目录" value="DIRECTORY" />
            <el-option label="菜单" value="MENU" />
            <el-option label="按钮" value="BUTTON" />
          </el-select>
        </el-form-item>
        
        <el-form-item label="父级菜单" prop="parentId">
          <el-tree-select
            v-model="menuForm.parentId"
            :data="parentMenuOptions"
            :props="{ label: 'menuName', value: 'id', children: 'children' }"
            placeholder="请选择父级菜单（不选择则为顶级菜单）"
            clearable
            check-strictly
            style="width: 100%"
          />
        </el-form-item>
        
        <el-form-item label="路由路径" prop="path" v-if="menuForm.menuType !== 'BUTTON'">
          <el-input v-model="menuForm.path" placeholder="请输入路由路径" />
        </el-form-item>
        
        <el-form-item label="组件路径" prop="component" v-if="menuForm.menuType === 'MENU'">
          <el-input v-model="menuForm.component" placeholder="请输入组件路径" />
        </el-form-item>
        
        <el-form-item label="图标" prop="icon">
          <el-input v-model="menuForm.icon" placeholder="请输入图标名称">
            <template #prepend>
              <el-icon v-if="menuForm.icon">
                <component :is="menuForm.icon" />
              </el-icon>
            </template>
          </el-input>
        </el-form-item>
        
        <el-form-item label="排序" prop="sort">
          <el-input-number v-model="menuForm.sort" :min="0" style="width: 100%" />
        </el-form-item>
        
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="menuForm.status">
            <el-radio :label="1">启用</el-radio>
            <el-radio :label="0">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
        
        <el-form-item label="描述" prop="description">
          <el-input 
            v-model="menuForm.description" 
            type="textarea" 
            :rows="3"
            placeholder="请输入菜单描述"
          />
        </el-form-item>
      </el-form>
      
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="handleSubmit" :loading="submitLoading">
            确定
          </el-button>
        </span>
      </template>
    </el-dialog>

    <!-- 使用说明对话框 -->
    <el-dialog
      title="菜单管理使用说明"
      v-model="documentationVisible"
      width="1200px"
      :close-on-click-modal="false"
      class="documentation-dialog"
    >
      <div v-loading="documentationLoading" class="documentation-content">
        <div v-if="documentationData">
          <!-- 统计信息 -->
          <div class="statistics-section">
            <h3>📊 系统菜单统计</h3>
            <div class="statistics-grid">
              <div class="stat-item">
                <div class="stat-value">{{ documentationData.statistics.totalMenus }}</div>
                <div class="stat-label">菜单总数</div>
              </div>
              <div class="stat-item">
                <div class="stat-value">{{ documentationData.statistics.directoryCount }}</div>
                <div class="stat-label">目录数量</div>
              </div>
              <div class="stat-item">
                <div class="stat-value">{{ documentationData.statistics.menuCount }}</div>
                <div class="stat-label">菜单数量</div>
              </div>
              <div class="stat-item">
                <div class="stat-value">{{ documentationData.statistics.buttonCount }}</div>
                <div class="stat-label">按钮权限</div>
              </div>
              <div class="stat-item">
                <div class="stat-value">{{ documentationData.statistics.enabledCount }}</div>
                <div class="stat-label">已启用</div>
              </div>
              <div class="stat-item">
                <div class="stat-value">{{ documentationData.statistics.disabledCount }}</div>
                <div class="stat-label">已禁用</div>
              </div>
            </div>
          </div>

          <!-- 菜单类型说明 -->
          <div class="type-docs-section">
            <h3>📖 菜单类型说明</h3>
            <div class="type-docs-grid">
              <div 
                v-for="typeDoc in documentationData.menuTypeDocuments" 
                :key="typeDoc.type"
                class="type-doc-card"
              >
                <div class="type-doc-header">
                  <el-tag 
                    :type="getMenuTypeTagType(typeDoc.type)"
                    size="large"
                  >
                    {{ typeDoc.typeName }}
                  </el-tag>
                </div>
                <div class="type-doc-body">
                  <p class="description">{{ typeDoc.description }}</p>
                  
                  <div class="usage-section">
                    <h4>使用场景</h4>
                    <p>{{ typeDoc.usage }}</p>
                  </div>
                  
                  <div class="examples-section">
                    <h4>示例</h4>
                    <ul>
                      <li v-for="example in typeDoc.examples" :key="example">
                        {{ example }}
                      </li>
                    </ul>
                  </div>
                  
                  <div class="notes-section">
                    <h4>注意事项</h4>
                    <p class="notes">{{ typeDoc.notes }}</p>
                  </div>
                </div>
              </div>
            </div>
          </div>

                    <!-- 当前系统菜单结构 -->
          <div class="menu-structure-section">
            <h3>🗂️ 当前系统菜单结构</h3>
            <div class="menu-structure-container">
              <div class="menu-tree-info">
                <p>以下展示了当前系统中的所有菜单结构，采用简洁的树形层级展示：</p>
              </div>
              
              <!-- 简洁的树形菜单结构 -->
              <div class="clean-menu-tree">
                <div class="menu-hierarchy">
                  <div v-for="menu in documentationData.menuTree" :key="menu.id" class="menu-group">
                    
                    <!-- 顶级菜单（目录） -->
                    <div class="top-level-menu" :class="getTopLevelClass(menu)">
                      <div class="menu-header">
                        <div class="menu-title-section">
                          <el-icon v-if="menu.icon" class="menu-icon">
                            <component :is="menu.icon" />
                          </el-icon>
                          <span class="menu-title">{{ menu.menuName }}</span>
                          <el-tag :type="getMenuTypeTagType(menu.menuType)" size="small" class="type-badge">
                            {{ getMenuTypeText(menu.menuType) }}
                          </el-tag>
                        </div>
                        <div class="menu-meta">
                          <span class="meta-item">路径: <code>{{ menu.path || '无' }}</code></span>
                          <span class="meta-item">排序: <span class="sort-num">{{ menu.sort }}</span></span>
                        </div>
                      </div>
                    </div>
                    
                    <!-- 子菜单列表 -->
                    <div v-if="menu.children && menu.children.length > 0" class="sub-menu-list">
                      <div v-for="child in menu.children" :key="child.id" class="sub-menu-item">
                        
                        <!-- 子菜单主体 -->
                        <div class="sub-menu-main" :class="getSubMenuClass(child)">
                          <div class="sub-menu-info">
                            <div class="connector-line"></div>
                            <div class="sub-menu-content">
                              <div class="sub-menu-header">
                                <el-icon v-if="child.icon" class="sub-menu-icon">
                                  <component :is="child.icon" />
                                </el-icon>
                                <span class="sub-menu-name">{{ child.menuName }}</span>
                                <el-tag :type="getMenuTypeTagType(child.menuType)" size="small">
                                  {{ getMenuTypeText(child.menuType) }}
                                </el-tag>
                              </div>
                              <div class="sub-menu-details">
                                <div class="detail-row">
                                  <span class="detail-label">路径:</span>
                                  <code class="detail-code">{{ child.path || '无' }}</code>
                                </div>
                                <div class="detail-row" v-if="child.component">
                                  <span class="detail-label">组件:</span>
                                  <code class="detail-code">{{ child.component }}</code>
                                </div>
                                <div class="detail-row">
                                  <span class="detail-label">排序:</span>
                                  <span class="sort-badge">{{ child.sort }}</span>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                        
                        <!-- 按钮权限区域 -->
                        <div v-if="child.children && child.children.length > 0" class="button-permissions-area">
                          <div class="permissions-header">
                            <span class="permissions-label">按钮权限</span>
                            <span class="permissions-count">({{ child.children.length }}个)</span>
                          </div>
                          <div class="permissions-grid">
                            <div 
                              v-for="button in child.children" 
                              :key="button.id" 
                              class="permission-card"
                              :class="{ 'permission-disabled': button.status === 0 }"
                            >
                              <div class="permission-info">
                                <span class="permission-name">{{ button.menuName }}</span>
                                <code class="permission-code">{{ button.menuCode }}</code>
                              </div>
                              <el-tag 
                                :type="button.status === 1 ? 'success' : 'danger'"
                                size="small"
                                class="permission-status"
                              >
                                {{ button.status === 1 ? '启用' : '禁用' }}
                              </el-tag>
                            </div>
                          </div>
                        </div>
                        
                      </div>
                    </div>
                    
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="documentationVisible = false">关闭</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Plus, Refresh, Edit, Delete, Document, Folder } from '@element-plus/icons-vue'
import request from '../utils/request'

// 响应式数据
const loading = ref(false)
const submitLoading = ref(false)
const dialogVisible = ref(false)
const dialogTitle = ref('')
const menuData = ref([])
const parentMenuOptions = ref([])
const expandedKeys = ref([])
const menuFormRef = ref()

// 说明文档相关
const documentationVisible = ref(false)
const documentationLoading = ref(false)
const documentationData = ref(null)

// 菜单表单
const menuForm = reactive({
  id: null,
  menuName: '',
  menuCode: '',
  parentId: null,
  menuType: 'MENU',
  path: '',
  component: '',
  icon: '',
  sort: 0,
  status: 1,
  description: ''
})

// 表单验证规则
const menuFormRules = {
  menuName: [
    { required: true, message: '请输入菜单名称', trigger: 'blur' }
  ],
  menuCode: [
    { required: true, message: '请输入菜单编码', trigger: 'blur' }
  ],
  menuType: [
    { required: true, message: '请选择菜单类型', trigger: 'change' }
  ],
  path: [
    { 
      validator: (rule, value, callback) => {
        if (menuForm.menuType !== 'BUTTON' && !value) {
          callback(new Error('请输入路由路径'))
        } else {
          callback()
        }
      }, 
      trigger: 'blur' 
    }
  ],
  component: [
    { 
      validator: (rule, value, callback) => {
        if (menuForm.menuType === 'MENU' && !value) {
          callback(new Error('请输入组件路径'))
        } else {
          callback()
        }
      }, 
      trigger: 'blur' 
    }
  ]
}

// 获取菜单数据
const fetchMenuData = async () => {
  try {
    loading.value = true
    const response = await request.get('/admin/menu-management/tree')
    menuData.value = response.data
  } catch (error) {
    console.error('获取菜单数据失败:', error)
    ElMessage.error('获取菜单数据失败')
  } finally {
    loading.value = false
  }
}

// 获取父级菜单选项
const fetchParentMenuOptions = async () => {
  try {
    const response = await request.get('/admin/menu-management/parent-options')
    parentMenuOptions.value = response.data
  } catch (error) {
    console.error('获取父级菜单选项失败:', error)
    ElMessage.error('获取父级菜单选项失败')
  }
}

// 刷新数据
const refreshData = () => {
  fetchMenuData()
  fetchParentMenuOptions()
}

// 处理展开/收起
const handleExpandChange = (row, expandedRows) => {
  expandedKeys.value = expandedRows.map(item => item.id)
}

// 新增菜单
const handleAdd = () => {
  dialogTitle.value = '新增菜单'
  resetForm()
  dialogVisible.value = true
}

// 编辑菜单
const handleEdit = async (row) => {
  dialogTitle.value = '编辑菜单'
  try {
    const response = await request.get(`/admin/menu-management/${row.id}`)
    const menuData = response.data
    
    Object.keys(menuForm).forEach(key => {
      menuForm[key] = menuData[key] || (key === 'sort' ? 0 : (key === 'status' ? 1 : ''))
    })
    
    dialogVisible.value = true
  } catch (error) {
    console.error('获取菜单详情失败:', error)
    ElMessage.error('获取菜单详情失败')
  }
}

// 删除菜单
const handleDelete = async (row) => {
  try {
    await ElMessageBox.confirm(`确定要删除菜单 "${row.menuName}" 吗？`, '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    
    await request.delete(`/admin/menu-management/${row.id}`)
    ElMessage.success('删除菜单成功')
    fetchMenuData()
  } catch (error) {
    if (error.response) {
      ElMessage.error(error.response.data?.message || '删除菜单失败')
    }
    // 用户取消操作不显示错误
  }
}

// 提交表单
const handleSubmit = async () => {
  try {
    await menuFormRef.value.validate()
    submitLoading.value = true
    
    const formData = { ...menuForm }
    
    // 如果是按钮类型，清空路由路径和组件路径
    if (formData.menuType === 'BUTTON') {
      formData.path = ''
      formData.component = ''
    }
    
    // 如果不是菜单类型，清空组件路径
    if (formData.menuType !== 'MENU') {
      formData.component = ''
    }
    
    if (formData.id) {
      // 编辑
      await request.put(`/admin/menu-management/${formData.id}`, formData)
      ElMessage.success('更新菜单成功')
    } else {
      // 新增
      await request.post('/admin/menu-management', formData)
      ElMessage.success('新增菜单成功')
    }
    
    dialogVisible.value = false
    fetchMenuData()
    fetchParentMenuOptions()
  } catch (error) {
    console.error('提交表单失败:', error)
  } finally {
    submitLoading.value = false
  }
}

// 重置表单
const resetForm = () => {
  Object.keys(menuForm).forEach(key => {
    menuForm[key] = key === 'sort' ? 0 : (key === 'status' ? 1 : (key === 'menuType' ? 'MENU' : ''))
  })
  menuForm.id = null
  
  if (menuFormRef.value) {
    menuFormRef.value.clearValidate()
  }
}

// 获取菜单类型标签类型
const getMenuTypeTagType = (type) => {
  switch (type) {
    case 'DIRECTORY':
      return 'warning'
    case 'MENU':
      return 'primary'
    case 'BUTTON':
      return 'success'
    default:
      return 'info'
  }
}

// 获取菜单类型文本
const getMenuTypeText = (type) => {
  switch (type) {
    case 'DIRECTORY':
      return '目录'
    case 'MENU':
      return '菜单'
    case 'BUTTON':
      return '按钮'
    default:
      return '未知'
  }
}

// 获取顶级菜单样式类
const getTopLevelClass = (menu) => {
  return {
    [`top-level-${menu.menuType?.toLowerCase()}`]: true,
    'top-level-disabled': menu.status === 0
  }
}

// 获取子菜单样式类
const getSubMenuClass = (menu) => {
  return {
    [`sub-menu-${menu.menuType?.toLowerCase()}`]: true,
    'sub-menu-disabled': menu.status === 0
  }
}

// 格式化日期时间
const formatDateTime = (dateTime) => {
  if (!dateTime) return ''
  return new Date(dateTime).toLocaleString('zh-CN')
}

// 显示使用说明
const showDocumentation = async () => {
  documentationVisible.value = true
  await fetchDocumentation()
}

// 获取说明文档数据
const fetchDocumentation = async () => {
  try {
    documentationLoading.value = true
    const response = await request.get('/admin/menu-management/documentation')
    documentationData.value = response.data
  } catch (error) {
    console.error('获取说明文档失败:', error)
    ElMessage.error('获取说明文档失败')
  } finally {
    documentationLoading.value = false
  }
}



// 页面加载时获取数据
onMounted(() => {
  fetchMenuData()
  fetchParentMenuOptions()
})
</script>

<style scoped>
.menu-management {
  background: white;
  border-radius: 8px;
  padding: 20px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #e6e6e6;
}

.page-header h2 {
  margin: 0;
  color: #333;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.table-container {
  margin-top: 20px;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

:deep(.el-table .el-table__row) {
  cursor: pointer;
}

:deep(.el-tree-select .el-select__placeholder) {
  color: #a8abb2;
}

/* 表格展开收缩动画 */
.animated-table :deep(.el-table__expand-icon) {
  transition: all 0.3s ease;
  color: #409EFF;
}

.animated-table :deep(.el-table__expand-icon.is-leaf) {
  color: transparent;
}

.animated-table :deep(.el-table__expand-icon--expanded) {
  transform: rotate(90deg);
}

.animated-table :deep(.el-table__expand-icon:hover) {
  color: #66b1ff;
  transform: scale(1.1);
}

.animated-table :deep(.el-table__expand-icon--expanded:hover) {
  transform: rotate(90deg) scale(1.1);
}

.animated-table :deep(.el-table__row) {
  transition: all 0.3s ease;
}

.animated-table :deep(.el-table__row:hover) {
  background-color: #f0f7ff;
  transform: translateX(2px);
}

.animated-table :deep(.el-table__row:hover .el-table__cell) {
  border-color: #409EFF;
}

/* 表格行展开动画 */
.animated-table :deep(.el-table__expanded-cell) {
  animation: tableRowExpand 0.3s ease;
}

@keyframes tableRowExpand {
  0% {
    opacity: 0;
    transform: translateY(-10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 说明文档对话框样式 */
.documentation-dialog {
  :deep(.el-dialog__body) {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
  }
}

.documentation-content {
  color: #333;
}

.documentation-content h3 {
  color: #409EFF;
  margin-bottom: 20px;
  border-bottom: 2px solid #e6e6e6;
  padding-bottom: 10px;
}

/* 统计信息样式 */
.statistics-section {
  margin-bottom: 30px;
}

.statistics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.stat-item {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px;
  border-radius: 10px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.stat-item:hover {
  transform: translateY(-5px);
}

.stat-value {
  font-size: 2em;
  font-weight: bold;
  margin-bottom: 5px;
}

.stat-label {
  font-size: 0.9em;
  opacity: 0.9;
}

/* 菜单类型说明样式 */
.type-docs-section {
  margin-bottom: 30px;
}

.type-docs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.type-doc-card {
  border: 1px solid #e6e6e6;
  border-radius: 8px;
  overflow: hidden;
  transition: box-shadow 0.3s ease;
  background: white;
}

.type-doc-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.type-doc-header {
  background: #f8f9fa;
  padding: 15px;
  border-bottom: 1px solid #e6e6e6;
}

.type-doc-body {
  padding: 20px;
}

.type-doc-body .description {
  color: #666;
  margin-bottom: 15px;
  font-size: 1em;
  line-height: 1.6;
}

.usage-section,
.examples-section,
.notes-section {
  margin-bottom: 15px;
}

.usage-section h4,
.examples-section h4,
.notes-section h4 {
  color: #409EFF;
  margin-bottom: 8px;
  font-size: 0.9em;
  font-weight: 600;
}

.examples-section ul {
  margin: 0;
  padding-left: 20px;
}

.examples-section li {
  margin-bottom: 5px;
  color: #666;
  font-size: 0.9em;
}

.notes {
  color: #e6a23c;
  font-style: italic;
  font-size: 0.9em;
}

/* 菜单结构样式 */
.menu-structure-section {
  margin-bottom: 20px;
}

.menu-structure-container {
  border: 1px solid #e6e6e6;
  border-radius: 8px;
  padding: 20px;
  background: #fafafa;
}

.menu-tree-info {
  margin-bottom: 15px;
  color: #666;
}

/* 清晰菜单层次结构样式 */
.clean-menu-tree {
  background: #fafbfc;
  border-radius: 12px;
  padding: 24px;
  border: 1px solid #e1e8ed;
  max-height: 650px;
  overflow-y: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.menu-hierarchy {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.menu-group {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #e8eef5;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

/* 顶级菜单样式 */
.top-level-menu {
  padding: 0;
  border-bottom: 2px solid;
}

.top-level-directory {
  border-bottom-color: #fa8c16;
  background: linear-gradient(135deg, #fff7e6 0%, #ffeec7 100%);
}

.top-level-menu {
  border-bottom-color: #1890ff;
  background: linear-gradient(135deg, #e6f7ff 0%, #cce7ff 100%);
}

.top-level-button {
  border-bottom-color: #52c41a;
  background: linear-gradient(135deg, #f6ffed 0%, #e6f7d3 100%);
}

.top-level-disabled {
  opacity: 0.6;
  background: linear-gradient(135deg, #f5f5f5 0%, #eeeeee 100%) !important;
  border-bottom-color: #d9d9d9 !important;
}

.menu-header {
  padding: 20px 24px;
}

.menu-title-section {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.menu-icon {
  color: #434343;
  font-size: 24px;
  flex-shrink: 0;
}

.menu-title {
  font-size: 20px;
  font-weight: 700;
  color: #262626;
  flex: 1;
}

.type-badge {
  font-weight: 600;
  font-size: 12px;
}

.menu-meta {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: #595959;
}

.meta-item code {
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 13px;
  color: #434343;
}

.sort-num {
  background: #f0f2f5;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  color: #434343;
}

/* 子菜单列表 */
.sub-menu-list {
  background: #f8f9fa;
  padding: 16px 0;
}

.sub-menu-item {
  margin-bottom: 16px;
}

.sub-menu-item:last-child {
  margin-bottom: 0;
}

.sub-menu-main {
  margin: 0 20px;
  background: white;
  border-radius: 8px;
  border-left: 4px solid;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  transition: all 0.3s ease;
}

.sub-menu-main:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

.sub-menu-directory {
  border-left-color: #fa8c16;
}

.sub-menu-menu {
  border-left-color: #1890ff;
}

.sub-menu-button {
  border-left-color: #52c41a;
}

.sub-menu-disabled {
  opacity: 0.6;
  background: #f5f5f5 !important;
  border-left-color: #d9d9d9 !important;
}

.sub-menu-info {
  display: flex;
  align-items: flex-start;
  padding: 16px 20px;
}

.connector-line {
  width: 24px;
  height: 2px;
  background: #e8e8e8;
  margin-top: 12px;
  margin-right: 16px;
  position: relative;
  flex-shrink: 0;
}

.connector-line::before {
  content: '';
  position: absolute;
  left: -20px;
  top: -10px;
  width: 2px;
  height: 24px;
  background: #e8e8e8;
}

.sub-menu-content {
  flex: 1;
  min-width: 0;
}

.sub-menu-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.sub-menu-icon {
  color: #409EFF;
  font-size: 18px;
  flex-shrink: 0;
}

.sub-menu-name {
  font-size: 16px;
  font-weight: 600;
  color: #262626;
  flex: 1;
  min-width: 0;
}

.sub-menu-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.detail-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e8e8e8;
}

.detail-label {
  color: #595959;
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
}

.detail-code {
  color: #262626;
  background: white;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  border: 1px solid #d9d9d9;
}

.sort-badge {
  background: #1890ff;
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

/* 按钮权限区域 */
.button-permissions-area {
  margin: 0 20px;
  background: white;
  border-radius: 8px;
  padding: 16px 20px;
  border: 1px solid #e8eef5;
  border-top: none;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.permissions-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f0f0f0;
}

.permissions-label {
  font-weight: 600;
  color: #262626;
  font-size: 14px;
}

.permissions-count {
  color: #8c8c8c;
  font-size: 12px;
}

.permissions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.permission-card {
  background: #fafafa;
  border: 1px solid #e8e8e8;
  border-radius: 6px;
  padding: 10px 12px;
  transition: all 0.3s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.permission-card:hover {
  border-color: #409EFF;
  box-shadow: 0 2px 6px rgba(64, 158, 255, 0.1);
  background: white;
}

.permission-disabled {
  opacity: 0.6;
  background: #f5f5f5 !important;
  border-color: #d9d9d9 !important;
}

.permission-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.permission-name {
  font-size: 13px;
  font-weight: 600;
  color: #262626;
}

.permission-code {
  font-size: 11px;
  color: #8c8c8c;
  background: rgba(0, 0, 0, 0.04);
  padding: 1px 4px;
  border-radius: 2px;
  font-family: 'Consolas', 'Monaco', monospace;
}

.permission-status {
  flex-shrink: 0;
  font-size: 11px;
}



/* 响应式设计 */
@media (max-width: 768px) {
  .documentation-dialog {
    :deep(.el-dialog) {
      width: 95vw !important;
      margin: 5vh auto;
    }
  }
  
  .statistics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .type-docs-grid {
    grid-template-columns: 1fr;
  }
  
  .clean-menu-tree {
    padding: 16px;
    max-height: 500px;
  }
  
  .menu-hierarchy {
    gap: 16px;
  }
  
  .menu-header {
    padding: 16px;
  }
  
  .menu-title-section {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .menu-title {
    font-size: 18px;
  }
  
  .menu-meta {
    flex-direction: column;
    gap: 8px;
  }
  
  .sub-menu-main {
    margin: 0 12px;
  }
  
  .sub-menu-info {
    padding: 12px 16px;
  }
  
  .connector-line {
    display: none;
  }
  
  .sub-menu-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .sub-menu-name {
    font-size: 14px;
  }
  
  .sub-menu-details {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  .button-permissions-area {
    margin: 0 12px;
    padding: 12px 16px;
  }
  
  .permissions-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  .permission-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px;
  }
  
  .permission-info {
    gap: 6px;
  }
}
</style> 